from rest_framework.serializers import ModelSerializer, SerializerMethodField
from ninja import Schema, Field

from apps.commom.good import GoodSerializer
from models.models import ShopCart


class ShopCartSerializer(ModelSerializer):
    good = SerializerMethodField()

    def get_good(self, obj):
        return GoodSerializer(obj.good).data

    class Meta:
        model = ShopCart
        fields = "__all__"


class AddShopCartSchema(Schema):
    good_id: int = Field(default=0, description="商品id")
    spec_id: int = Field(default=0, description="规格id")
    good_number: int = Field(default=0, description="数量")

